/**
 * ATuanZhang
 */
package com.atuanzhang.activity;

import java.util.List;

import org.huanglei.android.activity.BaseActivity;

import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.atuanzhang.R;
import com.atuanzhang.adapter.GoodsListAdapter;
import com.atuanzhang.bean.Goods;
import com.atuanzhang.service.CityService;
import com.atuanzhang.service.GoodsService;
import com.google.inject.Inject;

/**
 * @author huanglei
 * @date 2011-3-24 @
 */
public class MainActivity extends BaseActivity {
	
	private final Context me = this;

	@Inject
	private GoodsService goodsService = null;

	@Inject
	private CityService cityService = null;
	
	@Inject
	private LocationManager locationManager = null; 

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		setContentView(R.layout.android_main);
		
		super.onCreate(savedInstanceState);
		
		initLayout();
		
		initData();
	}

	private void initLayout() {

	}

	private void initData() {
		
		//List<City> cityList = cityService.findHotCitys();
		//GridView gridView = (GridView) findViewById(R.id.goodsList_gridview);
		ListView listView = (ListView) findViewById(R.id.goodsList_gridview);
		List<Goods> goodsList = goodsService.findGoodsByCity("");
		
		if(goodsList != null){
			listView.setAdapter(new GoodsListAdapter(me, goodsList));
		}else{
			Toast.makeText(getApplication(), "暂无数据，请稍候再试", Toast.LENGTH_SHORT).show();
		}
		
		 listView.setOnItemClickListener(new ItemClick());
		
	}
	
    /*
     * item上的OnClick事件
     */
    public final class ItemClick implements OnItemClickListener {
    	
        public void onItemClick(AdapterView<?> parent, View arg1, int position, long id) {
            
            ListView lview=(ListView)parent;
           
            TextView urlsiteTextView = (TextView) lview.findViewById(R.id.goods_url_text_view);
            
    		String loc = String.valueOf(urlsiteTextView.getTag());
    		
            Intent intent = new Intent();  
            intent.setClass(MainActivity.this, GoodsActivity.class);  
    		Bundle bundle = new Bundle();
    		
    		bundle.putString("loc", loc);
    		intent.putExtras(bundle);
    		
            startActivity(intent);
           
            //Toast.makeText(getApplicationContext(), loc +"", 1).show();
        }
    }



}
